package com.lehecai.core.search.type;

import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class SearchEntityKey extends IntegerBeanLabelItem {
	
	private static final Logger logger = LoggerFactory.getLogger(SearchEntityKey.class.getName());
    private static final long serialVersionUID = 2848541352805176366L;

    private static List<SearchEntityKey> _items = new ArrayList<SearchEntityKey>();
	
	private static List<SearchEntityKey> items;
	
	private static Map<String, SearchEntityKey> nameMap = new HashMap<String, SearchEntityKey>();

	protected SearchEntityKey(String name, int value) {
		super(SearchEntityKey.class.getName(), name, value);
		_items.add(this);
		
		nameMap.put(name, this);
	}
	
	public static SearchEntityKey getItem(int value){
		try {
			return (SearchEntityKey) SearchEntityKey.getResult(SearchEntityKey.class.getName(), value);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}
	
	public static SearchEntityKey getItemByName(String name) {
		if (nameMap.containsKey(name)) {
			return nameMap.get(name);
		}
		return null;
	}
	
	public static List<SearchEntityKey> getItems() {
		return items;
	}

	public final static SearchEntityKey LOTTERY_ORDER = new SearchEntityKey("lottery_order", 1);
	public final static SearchEntityKey USER_ORDER = new SearchEntityKey("user_order", 2);
    //充值流水
    public final static SearchEntityKey RECORD_RECHARGE = new SearchEntityKey("pg_record_recharge", 3);
	
	static {
		synchronized (_items) {
			items = Collections.unmodifiableList(_items);
		}
	}
}

